class Solution:
    def isAdditiveNumber(self, num: str) -> bool:
        if len(num) <= 2:
            return False
        length = len(num)
        for i in range(1, (length + 1) // 2):
            for j in range(1, length - 2 * i + 1):
                str1, str2, str_in = num[:i], num[i:i+j], num[i+j:]
                if j > 1 and str2.startswith("0"):
                    continue
                if self.search(str1, str2, str_in):
                    return True
            if str1.startswith("0"):
                return False
        return False

    def search(self, str1: str, str2: str, str_in: str):
        if not str_in:
            return True
        sum_num = str(int(str1) + int(str2))
        length = len(sum_num)
        if sum_num == str_in[:length]:
            return self.search(str2, sum_num, str_in[length:])
        else:
            return False


a = Solution()
print(a.isAdditiveNumber("112358"))
print(a.isAdditiveNumber("199100199"))
print(a.isAdditiveNumber("123"))
print(a.isAdditiveNumber("101"))
print(a.isAdditiveNumber("00000"))
print(a.isAdditiveNumber("011235"))
